home *** CD-ROM | disk | FTP | other *** search
- /*
- * tabmix.js
- *
- * original code by Hemiola SUN, further developed by onemen and CPU
- */
- var gIsFirefox35;
- var gIsFirefox36;
- var gIsFirefox37;
- // when bug 347930 landed replace gisToolbarMode with gIsFirefox(XX)
- var gisToolbarMode;
-
- function TM_init() {
- document.getElementById("goPopup").addEventListener("popupshowing", TMP_Places.historyMenuItemsTitle, false);
- // history menu open in new tab if the curren tab is locked
- var historyMenu = document.getElementById("goPopup").parentNode;
- if (historyMenu)
- historyMenu.setAttribute("oncommand", "TMP_Places.historyMenu(event);");
-
- // disable the "Open New Window action in Single Window Mode...
- var cmdNewWindow = document.getElementById("cmd_newNavigator");
- var originalNewNavigator = cmdNewWindow.getAttribute("oncommand");
- cmdNewWindow.setAttribute("oncommand","if (gSingleWindowMode) BrowserOpenTab(); else {" + originalNewNavigator + "}");
-
- // replace browser handlers with ours so it recognizes when tabs are acted on
- gBrowser.onTabBarDblClick = TM_onTabBarDblClick;
- gBrowser.onTabClick = TM_checkClick;
-
- if(gBrowser.moveTabTo)
- gBrowser.moveTabTo = gBrowser.TMmoveTabTo;
-
- gBrowser.closedTabs = [];
-
- gBrowser.onresize = tabBarWidthChange;
- document.getElementById("contentAreaContextMenu").addEventListener("popupshowing", TM_checkContentMenu, false);
-
- // override some of All-in-One Gestures function
- // override the duplicate tab function
- if (typeof aioDupTab == 'function')
- aioDupTab = function() { gBrowser.duplicateTab(gBrowser.mCurrentTab); };
-
- //override the duplicate in new window function
- if (typeof aioDupWindow == 'function')
- aioDupWindow = function() { gBrowser.duplicateInWindow(gBrowser.mCurrentTab); };
-
- //override the aioCloseWindow function
- if (typeof aioCloseWindow == 'function')
- aioCloseWindow = BrowserTryToCloseWindow;
-
- window.setTimeout(TMP_delayedStartup, 0);
-
- //Browser:Home open in new tab if the curren tab is locked
- window.BrowserHome = TM_BrowserHome;
-
- // add call to TMP_Sanitizer
- // nsBrowserGlue.js use loadSubScript to load Sanitizer so we need to add this here
- var cmd = document.getElementById("Tools:Sanitize");
- if (cmd)
- cmd.setAttribute("oncommand", cmd.getAttribute("oncommand") + " TMP_Sanitizer.tryToSanitize();");
-
- // if sessionStore disabled use TMP command
- window.undoCloseTab = function ct_window_undoCloseTab(aIndex, aWhere) {
- return TMP_ClosedTabs.undoCloseTab(aIndex, aWhere);
- };
-
- // clone autoreload popup
- let popup = document.getElementById("autoreload_popup");
- let clonePopup = popup.cloneNode(true);
- clonePopup.removeAttribute("id");
- let menu = document.getElementById("tm-autoreload_menu");
- if (menu)
- menu.appendChild(popup);
- let tabMenu = document.getElementById("tm-autoreloadTab_menu");
- if (tabMenu)
- tabMenu.appendChild(clonePopup);
-
- // we eval navigator-toolbox customizeDone in TMP_delayedStartup
- TMP_BrowserToolboxCustomizeDone();
-
- // Look for RSS/Atom News Reader
- TMP_LookForRSS();
- }
-
- // Create new items in the tab bar context menu
- function TM_creatMenuItems () {
- // getBrowser() here is for Firefox 3 we get here before BrowserStartup
- // from Firefox 3.5 window have getter for gBrowser
- if (!getBrowser().tabContextMenu) {
- gBrowser.tabContextMenu = document.getAnonymousElementByAttribute(gBrowser, "anonid", "tabContextMenu");
- }
- var tabContextMenu = gBrowser.tabContextMenu;
- tabContextMenu.setAttribute("onpopuphidden", tabContextMenu.getAttribute("onpopuphidden") + "if (event.target == this) TM_hidePopup();");
- tabContextMenu.addEventListener("popupshowing", Tm_checkTabClick, false);
- tabContextMenu.addEventListener("popupshown", TMP_tabContextMenuShown, false);
-
- tabContextMenu.setAttribute("id", "menuedit-tabContextMenu");
-
- if (gIsFirefox35) {
- // From Firefox 3.5.4pre we can not use anonymous menupopup from toolbar button
- // this hack enable tabmix to use tab context menu from tablist tollbar button
- gBrowser.mTabContainer.parentNode.insertBefore(gBrowser.tabContextMenu, gBrowser.mTabContainer);
-
- // to be compatible with firefox 3.0 we use our on move tab to new window
- // firefox don't have function to duplicate the tab to new windows
- // look in gBrowser.duplicateInWindow
- let item = document.getElementById("context_openTabInWindow");
- if (item) // make sure no one removed it before we do
- tabContextMenu.removeChild(item);
- }
-
- //XXX we don't need this...
- var separators = tabContextMenu.getElementsByTagName("xul:menuseparator");
- for (let i = 0; i < separators.length; i++ ) {
- separators[i].setAttribute("id", "original-separator-" + i);
- }
-
- if (gIsFirefox37) {
- // from Firefox 3.7 2009-09-11 there is gContextMenu.openLinkInCurrent in contentAreaContextMenu
- // move our menu to that position
- let openLinkInCurrent = document.getElementById("context-openlinkincurrent");
- let tabmix_menu = document.getElementById("tm-openlinkhere");
- openLinkInCurrent.parentNode.insertBefore(tabmix_menu, openLinkInCurrent);
- }
-
- // update context_newTab attribute
- var newTab = document.getElementById("context_newTab");
- newTab.setAttribute("_newtab", newTab.getAttribute("label"));
- newTab.setAttribute("_afterthis", document.getElementById("tm-separator").getAttribute("_afterthis"));
- newTab.setAttribute("tmp_iconic", "menuitem-iconic tabs-newbutton tabs-newbutton-menu tmp-icon");
- newTab.removeAttribute("xbl:inherits");
-
- // group the close-tab options together
- var closeTab = document.getElementById("context_closeTab");
- var closeOther = document.getElementById("context_closeOtherTabs");
- tabContextMenu.insertBefore( closeTab, closeOther );
-
- var newMenuItems = ["tm-duplicateTab","tm-duplicateinWin","tm-detachTab","tm-mergeWindowsTab","tm-renameTab",
- "tm-copyTabUrl", "tm-autoreloadTab_menu", "tm-reloadOther","tm-reloadLeft","tm-reloadRight","tm-separator",
- "tm-undoCloseList","tm-separator-2",
- "tm-closeAllTabs","tm-closeSimilar","tm-closeLeftTabs","tm-closeRightTabs",
- "tm-docShell","tm-freezeTab","tm-protectTab","tm-lockTab"];
-
- var newMenuOrders = [ 1, 2, 3, 4, 5, 6,
- 9, 11, 12, 13, 14,
- 15, 16,
- 18, 19, 21, 22,
- 24, 25, 26, 27];
-
- // insert new menuitems and separators
- for (let i = 0; i < newMenuItems.length; i++ ) {
- var newMenuItem = document.getElementById(newMenuItems[i]);
- tabContextMenu.insertBefore( newMenuItem, tabContextMenu.childNodes.item(newMenuOrders[i]));
- }
- // remove our empty popup
- var popup = document.getElementById("extTabMixPopup");
- popup.parentNode.removeChild(popup);
-
- // move context_undoCloseTab before tm-undoCloseList
- var _undoCloseTab = document.getElementById("context_undoCloseTab");
- _undoCloseTab.setAttribute("key", "key_undoCloseTab");
- tabContextMenu.insertBefore(_undoCloseTab, document.getElementById("tm-undoCloseList"));
- // we can't disable menus with command attribute
- _undoCloseTab.removeAttribute("command");
- _undoCloseTab.setAttribute("oncommand", "TMP_ClosedTabs.undoCloseTab();");
-
- // insret IE Tab menu-items before Bookmakrs menu-items or at the end if origSep2 is null
- if ("gIeTab" in window) {
- var aFunction = "createTabbarMenu" in IeTab.prototype ? "createTabbarMenu" : "init";
- if (aFunction in IeTab.prototype) {
- eval("IeTab.prototype." + aFunction +" ="+IeTab.prototype[aFunction].toString().replace(
- 'tabbarMenu.insertBefore(document.getElementById("ietab-tabbar-sep"), separator);',
- 'separator = document.getElementById("original-separator-2"); $&'
- ));
- }
- }
-
- // fix conflict with CookiePie extension
- if ("cookiepieContextMenu" in window && !cookiepieContextMenu.initialized)
- cookiepieContextMenu.init();
- }
-
- function TMP_openDialog(panel) {
- var tabmixOptionsWin = gWindowManager.getMostRecentWindow("mozilla:tabmixopt");
- if (tabmixOptionsWin) {
-
- var appearanceWin = gWindowManager.getMostRecentWindow("mozilla:tabmixopt-appearance");
- var filetypeWin = gWindowManager.getMostRecentWindow("mozilla:tabmixopt-filetype");
-
- if (!appearanceWin && !filetypeWin && panel > -1)
- tabmixOptionsWin.TM_selectTab(panel);
-
- var incompatibleBox = tabmixOptionsWin.document.getElementById("incompatible");
- var incompatibleStatus = incompatibleBox.collapsed;
-
- incompatibleBox.collapsed = getExtensions().length == 0;
- if (incompatibleStatus != incompatibleBox.collapsed)
- tabmixOptionsWin.sizeToContent();
-
- (appearanceWin || filetypeWin || tabmixOptionsWin).focus();
- }
- else {
- if(panel > -1)
- gTabmixPrefs.setIntPref('extensions.tabmix.selected_tab', panel);
-
- window.openDialog("chrome://tabmixplus/content/pref/pref-tabmix.xul", "Tab Mix Plus", "chrome,titlebar,toolbar,close,dialog=no");
- }
- }
-
- /*
- * functions to disable incompatible extensions
- * original code by mrtech local_install.js , code modified by onemen 2006-01-13
- */
- function disableExtensions(aWindow) {
- var warning_list = getExtensions();
-
- if (warning_list.length == 0) {
- return true;
- }
-
- try {
- warning_list.sort();
- } catch(ex) { }
-
- var i, extension, outStr = "";
- for ( i = 0; i < warning_list.length; i++ ) {
- extension = warning_list[i];
- outStr += " - " + extension._name + " " + extension._version + "\n";
- }
-
- var showatStart = gTabmixPrefs.getBoolPref("extensions.tabmix.disableIncompatible")
- var chkBoxState = showatStart ? CHECKBOX_CHECKED : CHECKBOX_UNCHECKED;
-
- var bundleID = "tmp-string-bundle"
- var _stingBundle = document.getElementById(bundleID);
- var title = _stingBundle.getString("incompatible.title");
- var msg = _stingBundle.getString("incompatible.msg0") + "\n"
- + _stingBundle.getString("incompatible.msg1") + "\n\n" + outStr + "\n\n";
- var chkBoxLabel = _stingBundle.getString("incompatible.chkbox.label");
- var buttons = [SessionManager.setLabel("incompatible.button0", bundleID),
- SessionManager.setLabel("incompatible.button1", bundleID)];
- buttons.push(SessionManager.setLabel("incompatible.button2", bundleID));
-
- var result = TM_PromptService([BUTTON_EXTRA1, HIDE_MENUANDTEXT, chkBoxState],[title, msg, "", chkBoxLabel, buttons.join("\n")], aWindow);
- if (result.checked != showatStart) {
- gTabmixPrefs.setBoolPref("extensions.tabmix.disableIncompatible", result.checked);
- nsIPrefServiceObj.savePrefFile(null); // store the pref immediately
- }
-
- if (result.button != BUTTON_CANCEL) {
- var extensionManager = Components.classes["@mozilla.org/extensions/manager;1"]
- .getService(Components.interfaces.nsIExtensionManager);
- for ( i = 0; i < warning_list.length; i++ ) {
- extension = warning_list[i];
- try{
- extensionManager.disableItem(extension._guid);
- } catch(e) {
- tmLog("error while disabled " + extension._name)
- }
- }
-
- var dataSource = extensionManager.datasource.QueryInterface(Components.interfaces.nsIRDFRemoteDataSource);
- if (dataSource)
- dataSource.Flush();
-
- if (result.button == BUTTON_EXTRA1 && canQuitApplication()) {
- var appStartup = Components.interfaces.nsIAppStartup;
- Components.classes["@mozilla.org/toolkit/app-startup;1"]
- .getService(appStartup).quit(appStartup.eRestart | appStartup.eAttemptQuit);
- }
- else {
- msg = _stingBundle.getString("incompatible.msg2");
- buttons = ["", SessionManager.setLabel("sm.button.continue")].join("\n");
- TM_PromptService([BUTTON_CANCEL, HIDE_MENUANDTEXT, HIDE_CHECKBOX],[title, msg, "", "", buttons], aWindow);
- }
-
- return true;
- }
- return false;
- }
-
- function getExtensions() {
-
- var guid_list = {};
- /*
- * The following extensions are integrated or incompatible with Tab Mix Plus
- *
- * Add extensions ID in lowercase.
- */
- guid_list['{00bdd586-51fb-4b06-9c23-af2fb7609bf3}'] = true; // Basics
- guid_list['{b98719b3-76d6-4bec-aeed-3ab542b23bd7}'] = true; // BlankLast
- guid_list['{47921160-3085-4023-a145-8ec466babfba}'] = true; // Click2Tab
- guid_list['{b0f9cad2-ebae-4685-b518-d3d9b41ea183}'] = true; // Close Tab On Double Click
- guid_list['ctc@clav.mozdev.org'] = true; // CTC
- guid_list['{61ed2a9a-39eb-4aaf-bd14-06dfbe8880c3}'] = true; // Duplicate Tab
- guid_list['flowtabs'] = true; // Flowing Tabs
- guid_list['{cd2b821e-19f9-40a7-ac5c-08d6c197fc43}'] = true; // FLST
- guid_list['{68e5dd30-a659-4987-99f9-eaf21f9d4140}'] = true; // LastTab
- guid_list['minit@dorando'] = true; // MiniT
- guid_list['minit-drag'] = true; // miniT-drag
- guid_list['minit-tabscroll@dorando'] = true; // miniT-tabscroll
- guid_list['new-tab-button-on-tab-bar@mikegoodspeed.com'] = true; // new tab button on tab bar
- guid_list['{66E978CD-981F-47DF-AC42-E3CF417C1467}'] = true; // new tab homepage
- guid_list['newtaburl@sogame.cat'] = true; // NewTabURL
- guid_list['{4b2867d9-2973-42f3-bd9b-5ad30127c444}'] = true; // Petite Tabbrowser Extensions
- guid_list['{888d99e7-e8b5-46a3-851e-1ec45da1e644}'] = true; // ReloadEvery
- guid_list['{aede9b05-c23c-479b-a90e-9146ed62d377}'] = true; // Reload Tab On Double-Click
- guid_list['{492aa940-beaa-11d8-9669-0800200c9a66}'] = true; // Scrollable Tabs
- guid_list['{eb922232-fd76-4eb0-bd5a-c1cba4238343}'] = true; // Single Window
- guid_list['{149C6CC6-EC62-4ebd-B719-3C2E867930C7}'] = true; // Stack style tabs
- guid_list['supert@studio17.wordpress.com'] = true; // superT
- guid_list['tabbin'] = true; // Tab Bin
- guid_list['{43520b8f-4107-4351-ac64-9bcc5eea24b9}'] = true; // Tab Clicking Options
- guid_list['{bea6d1a7-882d-425f-bc75-944e0063ff3b}'] = true; // Tab Mix [original one]
- guid_list['tabtowindow@sogame.cat'] = true; // Tab to window
- guid_list['tabx@clav.mozdev.org'] = true; // Tab X
- guid_list['{0b0b0da8-08ba-4bc6-987c-6bc9f4d8a81e}'] = true; // Tabbrowser Extensions
- guid_list['{9b9d2aaa-ae26-4447-a7a1-633a32b19ddd}'] = true; // Tabbrowser Preferences
- guid_list['tabdrag'] = true; // tabdrag-for-tablib
- guid_list['tabfx@chaosware.net'] = true; // TabFX
- guid_list['tabsopenrelative@jomel.me.uk'] = true; // Tabs open ralative
- guid_list['tablib'] = true; // tablib
- guid_list['{328bbe91-cb86-40b0-a3fd-2b39969f9faa}'] = true; // Undo Close Tab
- guid_list['undoclosetab@dorando'] = true; // Undo Close Tab
- guid_list['{99ec6690-8bb1-11da-a72b-0800200c9a66}'] = true; // Unread Tabs
- // updated 2009-08-01
- guid_list['undoclosedtabsbutton@supernova00.biz'] = true; // Undo closed button
- guid_list['remove-new-tab-button@forerunnerdesigns.com'] = true;// Remove new tab button
- guid_list['last-tab-close-button@victor.sacharin'] = true; // Last tab close button
-
- function prop(elm, str) {
- var arc = RDFService.GetResource("http://www.mozilla.org/2004/em-rdf#" + str);
- var target = extensionDS.GetTarget(elm, arc, true);
- if (target instanceof Components.interfaces.nsIRDFLiteral ||
- target instanceof Components.interfaces.nsIRDFInt)
- return target.Value;
- return null;
- }
-
- var RDFService = Components.classes["@mozilla.org/rdf/rdf-service;1"]
- .getService(Components.interfaces.nsIRDFService);
- var Container = Components.classes["@mozilla.org/rdf/container;1"]
- .getService(Components.interfaces.nsIRDFContainer);
- var extensionDS = Components.classes["@mozilla.org/extensions/manager;1"]
- .getService(Components.interfaces.nsIExtensionManager).datasource;
- var root = "urn:mozilla:item:";
-
- try { // in ff 1.0.x we can get error at startup
- Container.Init(extensionDS, RDFService.GetResource(root + "root"));
- } catch (e) {
- tmLog("error in getExtensions " + e);
- return [];
- }
-
- var elements = Container.GetElements();
- var extensionsArray = [];
-
- while (elements.hasMoreElements()) {
- var element=elements.getNext().QueryInterface(Components.interfaces.nsIRDFResource);
- var id = element.Value.replace(root, "");
- if (typeof guid_list[id.toLowerCase()] != "undefined") {
- var opType = prop(element, "opType");
- var disabled = prop(element, "userDisabled");
- if ((!disabled && opType != "needs-disable" && opType != "needs-uninstall") ||
- ( disabled && opType == "needs-enable")) {
- var name = prop(element, "name");
- name = name.charAt(0).toUpperCase() + name.substr(1);
- extensionsArray.push({_name: name, _guid: id, _version:prop(element, "version")});
- }
- }
- }
- return extensionsArray;
- }
-
- var TMP_eventListener = {
- init: function TMP_EL_init(aTabContainer) {
- window.addEventListener("load", this, false);
-
- /*
- * Session Manager extesion add tabs too soon for us to check isTabVisible properly
- * we get wrong scrollstatus at startup
- * we add flag to use in tabBrowser.mTabContainer.isTabVisible
- */
- aTabContainer.setAttribute("SM_restart", true);
-
- aTabContainer.addEventListener("SSTabRestoring", this, true);
- aTabContainer.addEventListener("SSTabClosing", this, true);
- aTabContainer.addEventListener("TabOpen", this, true);
- aTabContainer.addEventListener("TabClose", this, true);
- aTabContainer.addEventListener("TabSelect", this, true);
- // add event for mouse scrolling on tab bar, necessary for linux
- aTabContainer.addEventListener("DOMMouseScroll", this, false);
- if (/^Linux/.test(navigator.platform))
- document.getElementById("navigator-toolbox").addEventListener("DOMMouseScroll", this, false);
- },
-
- handleEvent: function TMP_EL_handleEvent(aEvent) {
- switch (aEvent.type) {
- case "SSTabRestoring":
- this.onSSTabRestoring(aEvent);
- break;
- case "SSTabClosing":
- this.onSSTabClosing(aEvent);
- break;
- case "TabOpen":
- this.onTabOpen(aEvent);
- break;
- case "TabClose":
- this.onTabClose(aEvent);
- break;
- case "TabSelect":
- this.onTabSelect(aEvent);
- break;
- case "DOMMouseScroll":
- this.onTabBarScroll(aEvent);
- break;
- case "load":
- try {
- this.onWindowOpen(aEvent);
- } catch (ex) {TMP_ASSERT(ex);}
- break;
- case "unload":
- this.onWindowClose(aEvent);
- break;
- case "fullscreen":
- this.onFullScreen(false);
- break;
- }
- },
-
- onWindowOpen: function TMP_EL_onWindowOpen() {
- window.removeEventListener("load", this, false);
- window.addEventListener("unload", this, false);
- window.addEventListener("fullscreen", this, true);
-
- // don't load tabmix into undock sidebar opened by ezsidebar extension
- var wintype = window.document.documentElement.getAttribute("windowtype");
- if (wintype == "mozilla:sidebar") return;
-
- // replace old Settings.
- // we must call this before any other tabmix function
- gTMPprefObserver.updateSettings();
-
- // init tabmix functions
- try {
- tablib.init();
- } catch (ex) {TMP_ASSERT(ex);}
- try {
- TMP_Places.init();
- } catch (ex) {TMP_ASSERT(ex);}
- try {
- TM_init();
- } catch (ex) {TMP_ASSERT(ex);}
- try {
- TMP_LastTab.init();
- } catch (ex) {TMP_ASSERT(ex);}
- try {
- TMP_TBP_init();
- } catch (ex) {TMP_ASSERT(ex);}
- try {
- TMP_DragAndDrop_init();
- } catch (ex) {TMP_ASSERT(ex);}
-
- //this window open form _restoreTab we use it only when sessionStore is off
- // we can drop this some day soon
- if ("tabmix_afterTabduplicated" in window && window.tabmix_afterTabduplicated && "tabmix_duplicatData" in window && window.tabmix_duplicatData)
- NW_waitForSessionHistory();
-
- var tabBar = gBrowser.mTabContainer;
-
- //temp fix for bug 347930 - change Tab strip to be a toolbar will landed
- // look in calssic.css -moz-padding-start: 3px;
- if (gisToolbarMode)
- tabBar.setAttribute("toolbarmode", "true");
-
- // fix bug in new tab button on right extension when we use multi row
- if ("newTabButtons" in window) {
- var newbuttonRight = document.getAnonymousElementByAttribute(tabBar, "id", "tabs-newbutton-right");
- var newbuttonEnd = document.getAnonymousElementByAttribute(tabBar, "id", "tabs-newbutton-end");
- if (newbuttonRight && newbuttonEnd)
- newbuttonEnd.parentNode.insertBefore(newbuttonRight, newbuttonEnd);
- }
-
- /*
- * Session Manager extesion add tabs too soon for us to check isTabVisible properly
- * we get wrong scrollstatus at startup
- * we add flag to use in tabBrowser.mTabContainer.isTabVisible
- */
- if ("gSessionManager" in window && TMP_SessionStore.isAfterRestart())
- setTimeout(function (_tabBar) { _tabBar.removeAttribute("SM_restart"); }, 0, tabBar);
- else
- tabBar.removeAttribute("SM_restart");
-
- if (/^Mac/.test(navigator.platform)) {
- tabBar.setAttribute("Mac", "true");
- /*
- * get Mac drop indicator marginBottom , Mac default thme have marginBottom: -24px
- *
- * with TreeStyleTab extension vertical tabbar mTabDropIndicatorBar.firstChild is null
- */
- var ib = gBrowser.mTabDropIndicatorBar;
- if (ib && ib.firstChild) {
- TabDNDObserver.marginBottom =
- parseInt(window.getComputedStyle(ib.firstChild, null).marginBottom.replace("px", ""));
- }
- }
-
- var skin = gTabmixPrefs.getCharPref("general.skins.selectedSkin");
- if (skin=="classic/1.0") {
- if (/^Mac/.test(navigator.platform))
- tabBar.setAttribute("classic", "v3Mac");
- else if (/^Linux/.test(navigator.platform)) {
- tabBar.setAttribute("classic", "v3Linux");
- tabBar.setAttribute("platform", "linux");
- }
- else {
- tabBar.setAttribute("classic", "v3");
- tabBar.setAttribute("platform", "xp");
- }
- }
- else { //XXX need to add theme list here
- var themes = /^(iPoxRemix|Ie8fox|Vfox3)/;
- if (themes.test(skin)) {
- // add backgroundrepeat Attribute for theme for use in multi-row
- tabBar.setAttribute("backgroundrepeat" , true);
- }
- }
-
- // for new tab icon on context menu
- TMP_setItem("context_newTab", "platform", tabBar.getAttribute("platform"));
-
- if (gIsFirefox35)
- tabBar.setAttribute("platform", "v35");
-
- /* Chromifox set tab-close-button to !important; */
- if (skin == "cfxec") {
- let sss = Cc["@mozilla.org/content/style-sheet-service;1"].getService(Ci.nsIStyleSheetService);
- let uri = gIOService.newURI("chrome://tabmixplus/skin/themes/chromifox.css", null, null);
- if (!sss.sheetRegistered(uri, sss.USER_SHEET))
- sss.loadAndRegisterSheet(uri, sss.USER_SHEET);
- }
-
- // don't remove maybe some themes use this with Tabmix
- tabBar.setAttribute("tabmix_firefox3" , true);
-
- // adjust attribute when we close 2nd tab (we left with only one) or when we open 2nd tab
- if (numberOfWindows() > 1)
- adjustOn2ndTab.closeButton(1);
-
- if (gSingleWindowMode)
- gTMPprefObserver.setSingleWindowUI();
-
- gTMPprefObserver.setMenuIcons();
- gTMPprefObserver.toggleKey("key_tm_slideShow", "extensions.tabmix.disableF8Key");
- gTMPprefObserver.toggleKey("key_tm_toggleFLST", "extensions.tabmix.disableF9Key");
- try {
- gTMPprefObserver.createColorRules();
- } catch (ex) {TMP_ASSERT(ex);}
- gTMPprefObserver.tabCloseButton();
- var position = tabxPrefs.getIntPref("newTabButton.position");
- if (position != 0)
- gTMPprefObserver.changeNewTabButtonSide(position);
- TMP_ClosedTabs.setButtonType(tabxPrefs.getBoolPref("undoCloseButton.menuonly"));
-
- gHideTabBar = tabxPrefs.getIntPref("hideTabbar");
- /*
- * In the first time TMP is running we need to match extensions.tabmix.hideTabbar to browser.tabs.autoHide.
- * extensions.tabmix.hideTabbar default is 1 "Hide tabbar when i have only one tab"
- * if browser.tabs.autoHide is false we need to make sure extensions.tabmix.hideTabbar is set to 0 "Never Hide tabbar:
- */
- if (!gTabmixPrefs.getBoolPref("browser.tabs.autoHide") && gHideTabBar == 1) {
- gHideTabBar = 0;
- tabxPrefs.setIntPref("hideTabbar", gHideTabBar);
- }
- else
- gTMPprefObserver.setAutoHidePref();
-
- window.setTimeout(function () {
- // initialize the value of "gTabBarWidth"
- gTabBarWidth = gBrowser.mTabContainer.boxObject.width;
- // only hide the tabbar after we catch the width
- if (gHideTabBar == 2)
- TMP_setStripVisibilityTo(false);
- }, 100);
-
- var newPosition = tabxPrefs.getIntPref("tabBarPosition");
- if (newPosition == 1)
- gTMPprefObserver.tabBarPositionChanged(newPosition);
- // In XP default theme alltabs-button is the highest object in the tab strip
- // we need a place-holder for the height in case the user hide alltabs-buttin
- var alltabsButton = document.getAnonymousElementByAttribute(tabBar, "anonid", "alltabs-button");
- if (alltabsButton) {// mAllTabsButton removed from gBrowser in firefox 3.5 by bug 347930
- var stripIsHidden = gTabmixPrefs.getBoolPref("browser.tabs.autoHide") && !gBrowser.getStripVisibility();
- if (stripIsHidden)
- gBrowser.setStripVisibilityTo(true);
- var alltabsPlaceHolder = document.getAnonymousElementByAttribute(tabBar, "id", "alltabs-place-holder");
- alltabsPlaceHolder.setAttribute("height", alltabsButton.parentNode.boxObject.height);
- if (stripIsHidden)
- gBrowser.setStripVisibilityTo(false);
- }
-
- // make sure "extensions.tabmix.undoClose" is true if "browser.sessionstore.max_tabs_undo" is not zero
- var sessionstoreUndoClose = gTabmixPrefs.getIntPref("browser.sessionstore.max_tabs_undo") > 0;
- if (sessionstoreUndoClose != tabxPrefs.getBoolPref("undoClose"))
- tabxPrefs.setBoolPref("undoClose", sessionstoreUndoClose);
-
- // progressMeter on tabs
- var progressMeterOnTabs = TMP_getBoolPref(tabxBranch, "progressMeter", true);
- tabBar.setAttribute("progressMeter", progressMeterOnTabs);
- document.getElementById("statusbar-progresspanel").
- setAttribute("hidden", TMP_getBoolPref(tabxBranch, "noprogress",false) && progressMeterOnTabs);
-
- TMupdateSettings(true);
-
- // tabmix Options in Tools menu
- document.getElementById("tabmix-menu").hidden = !tabxPrefs.getBoolPref("optionsToolMenu");
-
- SessionManager.updateSettings();
- },
-
- onSSTabRestoring: function TMP_EL_onSSTabRestoring(aEvent) {
- var aTab = aEvent.target;
-
- if (aTab.hasAttribute("_locked")) {
- if (aTab.getAttribute("_locked") == "true")
- aTab.setAttribute("locked", "true");
- else
- aTab.removeAttribute("locked");
- }
-
- // this function run before tab load, so onTabReloaded will run when onStateChange get STATE_STOP
- var reloadData = aTab.getAttribute("reload-data");
- if (reloadData) {
- reloadData = reloadData.split(" ");
- setupAutoReload(aTab);
- aTab.autoReloadEnabled = true;
- aTab.autoReloadURI = reloadData[0];
- aTab.autoReloadTime = reloadData[1];
- }
- },
-
- onSSTabClosing: function TMP_EL_onSSTabClosing(aEvent) {
- var aTab = aEvent.target;
-
- var browser = gBrowser.getBrowserForTab(aTab);
- var iconURL = browser.mIconURL;
- if (aTab.hasAttribute("busy") || aTab.getAttribute("image") != iconURL) {
- aTab.removeAttribute("busy");
- if (iconURL)
- aTab.setAttribute("image", iconURL);
- else if (!(/^https?:/.test(browser.currentURI.spec)))
- gBrowser.useDefaultIcon(aTab);
- }
-
- // fixed in sessionStore for firefox 3.5
- if (!gIsFirefox35 && aTab.label == gBrowser.mStringBundle.getString("tabs.loading"))
- gBrowser.setTabTitle(aTab);
- },
-
- onFullScreen: function TMP_EL_onFullScreen(aPositionChanged) {
- // add fullscr-bottom-toggler when tabbar is on the bottom
- var fullScrToggler = document.getElementById("fullscr-bottom-toggler");
- if (gTabbarPosition == 1 && (!window.fullScreen || aPositionChanged)) {
- if (!fullScrToggler) {
- fullScrToggler = document.createElement("toolbar");
- fullScrToggler.id = "fullscr-bottom-toggler";
- fullScrToggler.setAttribute("customizable", "false");
- var _toolbox = document.createElement("toolbox");
- _toolbox.appendChild(fullScrToggler);
- gBrowser.mTabBox.insertBefore(_toolbox, gBrowser.mTabBox.firstChild);
- eval("FullScreen.mouseoverToggle ="+FullScreen.mouseoverToggle.toString().replace(
- 'document.getElementById("fullscr-toggler").setAttribute("moz-collapsed", aShow);',
- '$& \
- document.getElementById("fullscr-bottom-toggler").setAttribute("moz-collapsed", aShow);'
- ));
- }
- fullScrToggler.addEventListener("mouseover", FullScreen._expandCallback, false);
- fullScrToggler.addEventListener("dragenter", FullScreen._expandCallback, false);
- fullScrToggler.setAttribute("moz-collapsed", "false");
- fullScrToggler.setAttribute("inFullscreen", "true");
- }
- else if (fullScrToggler && window.fullScreen) {
- fullScrToggler.removeEventListener("mouseover", FullScreen._expandCallback, false);
- fullScrToggler.removeEventListener("dragenter", FullScreen._expandCallback, false);
- fullScrToggler.removeAttribute("inFullscreen");
- if (FullScreen._isChromeCollapsed)
- document.getElementById("fullscr-bottom-toggler").setAttribute("moz-collapsed", "true");
- }
- },
-
- // Function to catch when new tabs are created and update tab icons if needed
- // In addition clicks and doubleclick events are trapped.
- onTabOpen: function TMP_EL_onTabOpen(aEvent) {
- var aTab = aEvent.target;
-
- // adjust attribute when we close 2nd tab (we left with only one) or when we open 2nd tab
- adjustOn2ndTab.closeButton(1);
-
- var showCloseButton = tabxPrefs.getBoolPref("tabXMode.enable");
- if (showCloseButton) {
- var closeButtonOptions = ["no-button","always","showhover","current","current_hover","always"];
- aTab.setAttribute("tabx", closeButtonOptions[addtabx]);
- }
-
- if (tabxleft)
- aTab.setAttribute("tabxleft", "on");
-
- if ( alwaysNewTab == 1 )
- aTab.setAttribute("locked", "true");
-
- this.onTabOpen_updateTabBar();
-
- // the hack in TreeStyleTab extension look for our tabxTabAdded function
- // we remove tabxTabAdded function and use TMP_eventListener.onTabOpen from 0.3.7pre.080815
- if ("TreeStyleTabBrowser" in window && gBrowser.treeStyleTab) {
- gBrowser.treeStyleTab.initTabAttributes(aTab);
- gBrowser.treeStyleTab.initTabContentsOrder(aTab);
- }
- },
-
- // TGM extention use it
- onTabOpen_updateTabBar: function TMP_EL_onTabOpen_updateTabBar() {
- //XXX underline the label bleed over the end when tab is to small and we have close button on the tab !!!!????
- if (!gBrowser.mTabContainer.hasAttribute("hideunderline") && !gBrowser.mTabContainer._timeout) {
- gBrowser.mTabContainer._timeout = window.setTimeout( function(tabBar) {
- toggleUnderlineTabsLabel();
- if (tabBar._timeout) {
- clearTimeout(tabBar._timeout);
- tabBar._timeout = null;
- }
- }, 50, gBrowser.mTabContainer);
- }
-
- if (gBrowser.mTabContainer.getAttribute("multibar") != "scrollbar")
- tabBarScrollStatus();
- checkBeforeAndAfter();
- },
-
- onTabClose: function TMP_EL_onTabClose(aEvent) {
- // aTab is the tab we are closing now
- var aTab = aEvent.target;
-
- // adjust attribute when we close 2nd tab
- adjustOn2ndTab.closeButton(2, aTab);
-
- var tabBar = gBrowser.mTabContainer;
-
- // if we close the 2nd tab and browser.tabs.autoHide is true reset all scroll and multi-row parameter
- // strip already collapsed at this point
- if (tabBar.childNodes.length == 2 && gTabmixPrefs.getBoolPref("browser.tabs.autoHide")) {
- tabBar.collapsedTabs = 0;
- setTabBarHeight(1);
- tabBar.removeAttribute("multibar");
- }
-
- this.onTabClose_updateTabBar(aTab);
- },
-
- // TGM extention use it
- onTabClose_updateTabBar: function TMP_EL_onTabClose_updateTabBar(aTab) {
- var tabBar = gBrowser.mTabContainer;
- if ( tabscroll != 2 ) {
- var _canScrollTabsLeft = tabBar.canScrollTabsLeft;
- var _canScrollTabsRight = tabBar.canScrollTabsRight;
- tabBar.collapsedTabs--;
- if (!_canScrollTabsLeft)
- tabBar.canScrollTabsLeft = false;
- if (!_canScrollTabsRight)
- tabBar.canScrollTabsRight = false;
-
- window.setTimeout( function() {
- tabBar.adjustScrollTabsLeft();
- tabBar.adjustScrollTabsRight();
- tabBar.adjustNewtabButtonvisibility();
- }, 50 );
- }
- else if (tabBar.hasAttribute("multibar")) {
- // don't update tabBar.collapsedTabs after timeout
- // we must do it live......
- if (aTab._tPos < tabBar.collapsedTabs)
- tabBar.collapsedTabs--;
- if (!tabBar._onCloseTimeout) {
- tabBar._onCloseTimeout = window.setTimeout( function TMP_onCloseTimeout() {
- if (tabBar._onCloseTimeout) {
- clearTimeout(tabBar._onCloseTimeout);
- tabBar._onCloseTimeout = null;
- }
- tabBarScrollStatus();
- checkBeforeAndAfter();
- }, 100);
- }
- }
- else if (tabBar.hasAttribute("disAllowNewtabbutton"))
- tabBar.removeAttribute("disAllowNewtabbutton");
-
- //XXX underline the label bleed over the end when tab is to small and we have close button on the tab !!!!????
- if (tabBar.hasAttribute("hideunderline"))
- window.setTimeout( function() {toggleUnderlineTabsLabel();}, 50);
-
- },
-
- onTabSelect: function TMP_EL_TabSelect(aEvent) {
- var tab = aEvent.target;
- var tabBar = gBrowser.mTabContainer;
- // update this functions after new tab select
- tabBar.nextTab = 1;
- tab.setAttribute("flst_id", new Date().getTime());
- if (!tab.hasAttribute("visited"))
- tab.setAttribute("visited", true);
- TMP_LastTab.OnSelect();
- SessionManager.tabSelected(true);
-
- if (tabBar.hasAttribute("multibar")) {
- var top = tabBar.topTabY;
- var tabRow = tabBar.getTabRowNumber(tab, top);
- var prev = tab.previousSibling, next = tab.nextSibling;
- if ( prev && tabRow != tabBar.getTabRowNumber(prev, top) )
- prev.removeAttribute("beforeselected");
- if ( next && tabRow != tabBar.getTabRowNumber(next, top) )
- next.removeAttribute("afterselected");
- }
-
- var tabsBottom = document.getAnonymousElementByAttribute(tabBar, "class", "tabs-bottom");
- if (tabsBottom)
- TMP_setItem(tabBar, "tabonbottom", tab.baseY >= tabsBottom.boxObject.y || null);
- },
-
- onTabBarScroll: function TMP_EL_onTabBarScroll(aEvent) {
- var tabBar = gBrowser.mTabContainer;
-
- for (var i = 0; i < tabBar.childNodes.length; i++)
- tabBar.childNodes[i].setAttribute("showbutton","off");
-
- var ScrollDirection = aEvent.detail > 0 ? 1 : -1;
- if (gTabmixPrefs.getBoolPref("extensions.tabmix.reversedScroll"))
- ScrollDirection = -1 * ScrollDirection;
-
- var shouldMoveFocus = gTabmixPrefs.getBoolPref("extensions.tabmix.enableScrollSwitch");
- if (shouldMoveFocus) {
- tabBar.advanceSelectedTab(ScrollDirection, true);
- }
- else if ("TreeStyleTabBrowser" in window) {
- return;
- }
- else if ( tabscroll != 2 )
- tabBar.collapsedTabs += ScrollDirection;
- else if ( tabscroll == 2 )
- tabBar.rowScroll(ScrollDirection);
-
- aEvent.stopPropagation();
- aEvent.preventDefault();
- },
-
- onWindowClose: function TMP_EL_onWindowClose() {
- window.removeEventListener("unload", this, false);
-
- if (!gIsFirefox35) {
- gBrowser.mTabDropIndicatorBar.removeEventListener('dragover', TMP_TabDragOver, true);
- gBrowser.mTabDropIndicatorBar.removeEventListener('dragdrop', TMP_TabDragDrop, true);
- }
-
- document.getElementById("goPopup").removeEventListener("popupshowing", TMP_Places.historyMenuItemsTitle, false);
-
- var isLastWindow = numberOfWindows() == 0;
- // we close tabmix dialog windows on exit
- if (isLastWindow) {
- Array.forEach(["tabmixopt-filetype", "tabmixopt-appearance", "tabmixopt"], function(aID) {
- var win = gWindowManager.getMostRecentWindow("mozilla:" + aID);
- if (win) {
- if (aID != "tabmixopt")
- win.close();
- else
- win.setTimeout(function(){win.close();},0);
- }
- });
- }
-
- // check if we need to sanitize on exit without prompt to user
- try {
- // if tryToSanitize is false and privacy.sanitize.promptOnSanitize is true
- // we call TMP_Sanitizer.sanitize from Firefox Sanitizer
- var tabmixSanitized = isLastWindow && gTabmixPrefs.getBoolPref("privacy.sanitize.sanitizeOnShutdown") && TMP_Sanitizer.tryToSanitize(true);
- }
- catch (ex) {
- tabmixSanitized = false;
- }
- if (!tabmixSanitized) {
- SessionManager.deinit(isLastWindow, false);
- SessionManager.windowIsClosing(true, isLastWindow, true, false);
- }
- if (gIsFirefox35) {
- var observerService = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
- observerService.notifyObservers(null, "browser-window-change-state", "closed");
- observerService.removeObserver(SessionManager, "browser-window-change-state");
- observerService.removeObserver(SessionManager, "private-browsing");
- observerService.removeObserver(SessionManager, "quit-application-requested");
- observerService.removeObserver(SessionManager, "browser-lastwindow-close-requested");
- if (SessionManager.afterExitPrivateBrowsing) {
- clearTimeout(SessionManager.afterExitPrivateBrowsing);
- SessionManager.afterExitPrivateBrowsing = null;
- }
- }
-
- document.getElementById("contentAreaContextMenu").removeEventListener("popupshowing", TM_checkContentMenu, false);
- var tabContextMenu = gBrowser.mStrip.firstChild.nextSibling;
- tabContextMenu.removeEventListener("popupshowing", Tm_checkTabClick, false);
- tabContextMenu.removeEventListener("popupshown", TMP_tabContextMenuShown, false);
-
- TMP_LastTab.deinit();
-
- window.removeEventListener("fullscreen", this, true);
- var fullScrToggler = document.getElementById("fullscr-bottom-toggler");
- if (fullScrToggler) {
- fullScrToggler.removeEventListener("mouseover", FullScreen._expandCallback, false);
- fullScrToggler.removeEventListener("dragenter", FullScreen._expandCallback, false);
- }
-
- gBrowser.mTabContainer.removeEventListener("SSTabRestoring", this, true);
- gBrowser.mTabContainer.removeEventListener("SSTabClosing", this, true);
- gBrowser.mTabContainer.removeEventListener("TabOpen", this, true);
- gBrowser.mTabContainer.removeEventListener("TabClose", this, true);
- gBrowser.mTabContainer.removeEventListener("TabSelect", this, true);
- gBrowser.mTabContainer.removeEventListener("DOMMouseScroll", this, false);
- if (/^Linux/.test(navigator.platform))
- document.getElementById("navigator-toolbox").removeEventListener("DOMMouseScroll", this, false);
-
- // TreeStyleTab extension add this to be compatible with old tabmix version
- // we call removeEventListener again here in case user close the window without opening new tabs
- if ("TreeStyleTabBrowser" in window)
- gBrowser.mTabContainer.removeEventListener('DOMNodeInserted', tabxTabAdded, true);
-
- gTMPprefObserver.removeObservers();
- }
-
- }
-
- /* for treeStyleTab extension look in treeStyleTab hacks.js
- we remove tabxTabAdded function and use TMP_eventListener.onTabOpen from 0.3.7pre.080815
- */
- function tabxTabAdded() {
- // remove eventListener added by treeStyleTab on first call to tabxTabAdded
- gBrowser.mTabContainer.removeEventListener('DOMNodeInserted', tabxTabAdded, true);
- return;
- }
-